<!DOCTYPE html>
<html xmlns:th="http://www.thymeleaf.org">
<head>
    <meta charset="UTF-8">
    <title>新增用户信息</title>
    <script th:src="@{/webjars/jquery/3.5.1/jquery.min.js}"></script>
    <script>

        $(function () {
            var flag = true;
            $("#pid").blur(function () {
                /*alert(123);*/
                url = "http://localhost:8080/kgc/item/pid/"+this.value;
                //ctxPath = [[@{/}]];
                $.get(url,{},function (data) {
                    /* alert(data);*/
                    if (data>0){
                        $("#s1").html("上级分类可使用")
                        flag = true;
                    }else if(data==0){
                        $("#s1").html("上级分类不可以使用")
                        flag = false;
                    }else{
                        $("#s1").html("系统繁忙,请稍后重试!")
                        flag = false;
                    }
                });


            })
            $("#b1").click(function(){
                if($("#name").val() == null || $("#name").val() == "" ||
                    $("#remark").val() == null || $("#remark").val() == "" ) {
                    alert("商品分类名称及描述为必填项!")
                    flag=false;
                }

                if (flag==true){
                    $("#form1").submit();
                }
            });
            $("#b2").click(function () {
                /*window.location.reload();*/
                window.location.href=window.location.href;
                return false;
            });



        });

    </script>
</head>
<body>

   <form id="form1" th:action="@{/item}" method="post" th:object="${item}">
        <h1 th:if="${item.id == null}">新增商品分类</h1>
        <div th:if="${item.id !=null}">
            <h1>修改商品分类</h1>
            <input type="hidden" th:field="*{id}">

            <input type="hidden" name="_method" value="PUT">
        </div>
        <p>分类名称:<input type="text" th:field="*{name}"></p>
       <p>上级分类id:<input type="text" th:field="*{pid}"><span id="s1"></span>
       <!--<select th:field="*{pid}" >
           <option th:each="itemList:${ItemList}" th:text="${itemList.pid}"
                   th:value="${itemList.pid}"></option>
       </select>-->
       </p>
        <p>分类说明:<input type="text" th:field="*{remark}"></p>
       <button id="b1" type="button">保存</button>  &nbsp; <button  type="reset">重置</button>
   </form>
</body>
</html>